<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/18/0018
 * Time: 8:56
 */

namespace app\sports_admin\controller;


use app\sports_admin\service\RegionService;
use think\Model;
use app\sports_admin\model\Region as RegionModel;
use app\sports_admin\model\SportsProject as SportsProjectModel;
use think\Request;

class Region extends Base
{
    protected $beforeActionList = [
        'isResource'=>['only'=>'index,province,openingprovince,city,openingcity,area,openingarea,save,saveinfo'],
        'operationSelect'=>['only'=>'index,province,city,area,save'],
        'operationUpdate'=>['only'=>'openingprovince,openingcity,openingarea,saveinfo']
    ];
    /*
     * 地区列表
     */
    public function index()
    {
        $id = intval(input('get.city')) ? intval(input('get.city')) : '';
        //开通的地区信息
        $data = (new RegionModel())->isPassRegion($id);
        //开通的省
        $province = RegionModel::province();
        return view('index',compact('data','province'));
    }
    /*
     * 开通省页面
     */
    public function province()
    {
        //查询城市信息
        $data = RegionModel::cityInfo(1);
        return view('province',compact('data'));
    }
    /*
     * 开通省
     */
    public function openingProvince(Request $request)
    {
        if($request->isAjax()){
            return RegionService::openingProvince();
        }
    }
    /*
     * 开通市页面
     */
    public function city()
    {
        //城市信息id
        $id = intval(input('get.id'));
        //查询城市信息
        $data = RegionModel::cityInfo($id);
        //查询项目信息
        $project = SportsProjectModel::field('id,title')->select();
        return view('city',compact('data','project'));
    }
    /*
     * 开通市
     */
    public function openingCity(Request $request)
    {
        if($request->isAjax()){
            return RegionService::openingCity();
        }
    }
    /*
     * 开通县/区页面
     */
    public function area()
    {
        //城市信息id
        $id = intval(input('get.id'));
        //查询城市信息
        $data = RegionModel::cityInfo($id);
        return view('area',compact('data'));
    }
    /*
     * 开通县/区
     */
    public function openingArea(Request $request)
    {
        if($request->isAjax()){
            return RegionService::openingArea();
        }
    }
    /*
     * 编辑区/县页面
     * @param $id 城市信息id
     */
    public function save()
    {
        $id = intval(input('get.id'));
        $cityInfo = RegionModel::where('id',$id)->find();
        return view('save',compact('cityInfo'));
    }
    /*
     * 修改区/县信息
     */
    public function saveInfo(Request $request)
    {
        if($request->isAjax()){
            return RegionService::saveInfo();
        }
    }

}